package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.app.Dialog;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ToastUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.adapter.BxAdapter;
import flc.ast.bean.MyBxBean;
import flc.ast.databinding.ActivityBuyCostBinding;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.view.container.StkRecycleView;

public class BuyCostActivity extends BaseAc<ActivityBuyCostBinding> {

    private int priceAll, taxAll, licenceAll, useTaxAll, bxAll = 1100, resultAll;//全款购车
    private int priceLoan, taxLoan, licenceLoan, useTaxLoan, bxLoan = 1100, loanAmount, sqfk;//贷款购车
    private int monthPay, sumAmount, payInterest, repayAmount;
    private double sfk = 0.3;//首付款百分比
    private double rate = 0.0354;//年利率
    private String selBxAll, selBxLoan, dialogBxAll, dialogBxLoan, selSfk, dialogSfk, selLoanYear, dialogLoanYear;
    private Dialog myBxAllDialog, myBxLoanDialog, myResultAllDialog, mySfkDialog, myLoanYearDialog, myResultLoanDialog;
    private BxAdapter bxAllAdapter, bxLoanAdapter, sfkAdapter, loanYearAdapter;
    private int selPositionBxAll, selPositionBxLoan, selPositionSfk, selPositionLoanYear = 1, selYear = 2;
    private int oldPositionBxAll, oldPositionBxLoan, oldPositionSfk, oldPositionLoanYear = 1;
    private boolean isAll = true;


    @Override
    protected int onCreate() {
        return R.layout.activity_buy_cost;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);
        mDataBinding.ivBuyCarCostBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.tvBuyAll.setOnClickListener(this);
        mDataBinding.tvBuyLoan.setOnClickListener(this);
        mDataBinding.llBxAll.setOnClickListener(this);
        mDataBinding.llBxLoan.setOnClickListener(this);
        mDataBinding.ivStartCompute.setOnClickListener(this);
        mDataBinding.llSfk.setOnClickListener(this);
        mDataBinding.llLoanYear.setOnClickListener(this);
        mDataBinding.etPriceAll.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                if (str.length() == 0) {
                    priceAll = 0;
                    taxAll = (int) (priceAll * 0.0885);
                    mDataBinding.tvBuyTaxAll.setText(taxAll + "");
                    return;
                }
                priceAll = Integer.parseInt(str);
                taxAll = (int) (priceAll * 0.0885);
                mDataBinding.tvBuyTaxAll.setText(taxAll + "");
            }
        });
        mDataBinding.etPriceLoan.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                if (str.length() == 0) {
                    priceLoan = 0;
                    taxLoan = (int) (priceLoan * 0.0885);
                    loanAmount = 0;
                    sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                    mDataBinding.tvBuyTaxLoan.setText(taxLoan + "");
                    mDataBinding.tvLoanAmount.setText(loanAmount + "");
                    mDataBinding.tvSqfk.setText(sqfk + "");
                    return;
                }
                priceLoan = Integer.parseInt(str);
                taxLoan = (int) (priceLoan * 0.0885);
                loanAmount = (int) (priceLoan * (1 - sfk));
                sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                mDataBinding.tvBuyTaxLoan.setText(taxLoan + "");
                mDataBinding.tvLoanAmount.setText(loanAmount + "");
                mDataBinding.tvSqfk.setText(sqfk + "");
            }
        });
        mDataBinding.etLicenceLoan.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                if (str.length() == 0) {
                    licenceLoan = 0;
                    sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                    mDataBinding.tvSqfk.setText(sqfk + "");
                    return;
                }
                licenceLoan = Integer.parseInt(str);
                sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                mDataBinding.tvSqfk.setText(sqfk + "");
            }
        });
        mDataBinding.etUseTaxLoan.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                String str = s.toString();
                if (str.length() == 0) {
                    useTaxLoan = 0;
                    sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                    mDataBinding.tvSqfk.setText(sqfk + "");
                    return;
                }
                useTaxLoan = Integer.parseInt(str);
                sqfk = priceLoan - loanAmount + taxLoan + licenceLoan + useTaxLoan + bxLoan;
                mDataBinding.tvSqfk.setText(sqfk + "");
            }
        });
        //全款购车交强险弹框
        bxAllDialog();
        //贷款购车交强险弹框
        bxLoanDialog();
        //贷款购车首付款弹框
        sfkDialog();
        //贷款购车贷款年限弹框
        loanYearDialog();
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvBuyAll:
                clearSelection();
                mDataBinding.tvBuyAll.setTextColor(Color.parseColor("#FF1F1F21"));
                mDataBinding.tvBuyAll.setTypeface(Typeface.DEFAULT_BOLD);
                mDataBinding.tvBuyAll.setBackgroundResource(R.drawable.shape_buy);
                mDataBinding.tvBuyBot.setBackgroundResource(R.drawable.shape_buy_bot);
                mDataBinding.llBuyAll.setVisibility(View.VISIBLE);
                mDataBinding.llBuyLoan.setVisibility(View.GONE);
                isAll = true;
                break;
            case R.id.tvBuyLoan:
                clearSelection();
                mDataBinding.tvBuyLoan.setTextColor(Color.parseColor("#FF1F1F21"));
                mDataBinding.tvBuyLoan.setTypeface(Typeface.DEFAULT_BOLD);
                mDataBinding.tvBuyLoan.setBackgroundResource(R.drawable.shape_buy2);
                mDataBinding.tvBuyBot.setBackgroundResource(R.drawable.shape_buy_bot2);
                mDataBinding.llBuyAll.setVisibility(View.GONE);
                mDataBinding.llBuyLoan.setVisibility(View.VISIBLE);
                isAll = false;
                break;
            case R.id.llBxAll://全款购车交强险
                myBxAllDialog.show();
                break;
            case R.id.ivDialogBxRight:
                selBxAll = dialogBxAll;
                selPositionBxAll = oldPositionBxAll;
                for (int i = 0; i < bxAllAdapter.getValidData().size(); i++) {
                    if (i == selPositionBxAll) {
                        bxAllAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        bxAllAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                bxAllAdapter.notifyDataSetChanged();
                if (selBxAll.equals(getString(R.string.buy_bx1))) {
                    bxAll = 1100;
                } else {
                    bxAll = 950;
                }
                mDataBinding.tvBxAll.setText(bxAll + " " + selBxAll);
                myBxAllDialog.dismiss();
                break;
            case R.id.tvDialogBxCancel:
                oldPositionBxAll = selPositionBxAll;
                for (int i = 0; i < bxAllAdapter.getValidData().size(); i++) {
                    if (i == selPositionBxAll) {
                        bxAllAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        bxAllAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                bxAllAdapter.notifyDataSetChanged();
                myBxAllDialog.dismiss();
                break;
            case R.id.ivStartCompute://开始计算
                if (isAll) {
                    computeAll();
                }else {
                    computeLoan();
                }
                break;
            case R.id.ivDialogResultAllCancel:
                myResultAllDialog.dismiss();
                break;
            case R.id.llBxLoan://贷款购车交强险
                myBxLoanDialog.show();
                break;
            case R.id.ivDialogBxLoanRight:
                selBxLoan = dialogBxLoan;
                selPositionBxLoan = oldPositionBxLoan;
                for (int i = 0; i < bxLoanAdapter.getValidData().size(); i++) {
                    if (i == selPositionBxLoan) {
                        bxLoanAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        bxLoanAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                bxLoanAdapter.notifyDataSetChanged();
                if (selBxLoan.equals(getString(R.string.buy_bx1))) {
                    bxLoan = 1100;
                } else {
                    bxLoan = 950;
                }
                mDataBinding.tvBxLoan.setText(bxLoan + " " + selBxLoan);
                myBxLoanDialog.dismiss();
                break;
            case R.id.tvDialogBxLoanCancel:
                oldPositionBxLoan = selPositionBxLoan;
                for (int i = 0; i < bxLoanAdapter.getValidData().size(); i++) {
                    if (i == selPositionBxLoan) {
                        bxLoanAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        bxLoanAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                bxLoanAdapter.notifyDataSetChanged();
                myBxLoanDialog.dismiss();
                break;
            case R.id.llSfk://贷款购车首付款
                mySfkDialog.show();
                break;
            case R.id.ivDialogSfkRight:
                selSfk = dialogSfk;
                selPositionSfk = oldPositionSfk;
                for (int i = 0; i < sfkAdapter.getValidData().size(); i++) {
                    if (i == selPositionSfk) {
                        sfkAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        sfkAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                sfkAdapter.notifyDataSetChanged();
                if (selSfk.equals(getString(R.string.sfk_text1))) {
                    sfk = 0.3;
                } else if (selSfk.equals(getString(R.string.sfk_text2))) {
                    sfk = 0.4;
                } else if (selSfk.equals(getString(R.string.sfk_text3))) {
                    sfk = 0.5;
                } else if (selSfk.equals(getString(R.string.sfk_text4))) {
                    sfk = 0.6;
                }
                mDataBinding.tvSfk.setText(selSfk);
                mySfkDialog.dismiss();
                break;
            case R.id.tvDialogSfkCancel:
                oldPositionSfk = selPositionSfk;
                for (int i = 0; i < sfkAdapter.getValidData().size(); i++) {
                    if (i == selPositionSfk) {
                        sfkAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        sfkAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                sfkAdapter.notifyDataSetChanged();
                mySfkDialog.dismiss();
                break;
            case R.id.llLoanYear://贷款购车贷款年限
                myLoanYearDialog.show();
                break;
            case R.id.ivDialogLoanYearRight:
                selLoanYear = dialogLoanYear;
                selPositionLoanYear = oldPositionLoanYear;
                for (int i = 0; i < loanYearAdapter.getValidData().size(); i++) {
                    if (i == selPositionLoanYear) {
                        loanYearAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        loanYearAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                loanYearAdapter.notifyDataSetChanged();
                if (selSfk.equals(getString(R.string.loan_year1))) {
                    selYear = 1;
                    rate = 0.036;
                } else if (selSfk.equals(getString(R.string.loan_year2))) {
                    selYear = 2;
                    rate = 0.0354;
                } else if (selSfk.equals(getString(R.string.loan_year3))) {
                    selYear = 3;
                    rate = 0.0353;
                } else if (selSfk.equals(getString(R.string.loan_year4))) {
                    selYear = 4;
                    rate = 0.0368;
                } else if (selSfk.equals(getString(R.string.loan_year5))) {
                    selYear = 5;
                    rate = 0.0371;
                }
                mDataBinding.tvLoanYear.setText(selLoanYear);
                myLoanYearDialog.dismiss();
                break;
            case R.id.tvDialogLoanYearCancel:
                oldPositionLoanYear = selPositionLoanYear;
                for (int i = 0; i < loanYearAdapter.getValidData().size(); i++) {
                    if (i == selPositionLoanYear) {
                        loanYearAdapter.getValidData().get(i).setSelected(true);
                    } else {
                        loanYearAdapter.getValidData().get(i).setSelected(false);
                    }
                }
                loanYearAdapter.notifyDataSetChanged();
                myLoanYearDialog.dismiss();
                break;
            case R.id.ivDialogResultLoanCancel:
                myResultLoanDialog.dismiss();
                break;
        }
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        if (adapter == bxAllAdapter) {
            bxAllAdapter.getItem(oldPositionBxAll).setSelected(false);
            bxAllAdapter.notifyItemChanged(oldPositionBxAll);
            oldPositionBxAll = position;
            dialogBxAll = bxAllAdapter.getItem(position).getText();
            bxAllAdapter.getItem(position).setSelected(true);
            bxAllAdapter.notifyItemChanged(position);
        } else if (adapter == bxLoanAdapter) {
            bxLoanAdapter.getItem(oldPositionBxLoan).setSelected(false);
            bxLoanAdapter.notifyItemChanged(oldPositionBxLoan);
            oldPositionBxLoan = position;
            dialogBxLoan = bxLoanAdapter.getItem(position).getText();
            bxLoanAdapter.getItem(position).setSelected(true);
            bxLoanAdapter.notifyItemChanged(position);
        } else if (adapter == sfkAdapter) {
            sfkAdapter.getItem(oldPositionSfk).setSelected(false);
            sfkAdapter.notifyItemChanged(oldPositionSfk);
            oldPositionSfk = position;
            dialogSfk = sfkAdapter.getItem(position).getText();
            sfkAdapter.getItem(position).setSelected(true);
            sfkAdapter.notifyItemChanged(position);
        } else if (adapter == loanYearAdapter) {
            loanYearAdapter.getItem(oldPositionLoanYear).setSelected(false);
            loanYearAdapter.notifyItemChanged(oldPositionLoanYear);
            oldPositionLoanYear = position;
            dialogLoanYear = loanYearAdapter.getItem(position).getText();
            loanYearAdapter.getItem(position).setSelected(true);
            loanYearAdapter.notifyItemChanged(position);
        }
    }

    @Override
    protected void initData() {
        selBxAll = getString(R.string.buy_bx1);
        selBxLoan = getString(R.string.buy_bx1);
        dialogBxAll = getString(R.string.buy_bx1);
        dialogBxLoan = getString(R.string.buy_bx1);
        selSfk = getString(R.string.sfk_text1);
        dialogSfk = getString(R.string.sfk_text1);
        selLoanYear = getString(R.string.loan_year2);
        dialogLoanYear = getString(R.string.loan_year2);
        mDataBinding.tvBxAll.setText(bxAll + " " + selBxAll);
        mDataBinding.tvBxLoan.setText(bxLoan + " " + selBxLoan);
        mDataBinding.tvSfk.setText(selSfk);
        mDataBinding.tvLoanYear.setText(selLoanYear);
    }

    private void computeAll() {
        if (mDataBinding.etPriceAll.getText().toString().isEmpty() || mDataBinding.etLicenceAll.getText().toString().isEmpty() || mDataBinding.etUseTaxAll.getText().toString().isEmpty()) {
            ToastUtils.showShort(getString(R.string.please_input_amount));
            return;
        }
        licenceAll = Integer.parseInt(mDataBinding.etLicenceAll.getText().toString());
        useTaxAll = Integer.parseInt(mDataBinding.etUseTaxAll.getText().toString());
        resultAll = priceAll + taxAll + licenceAll + useTaxAll + bxAll;
        resultAllDialog();
        myResultAllDialog.show();
    }

    private void computeLoan() {
        if (mDataBinding.etPriceLoan.getText().toString().isEmpty() || mDataBinding.etLicenceLoan.getText().toString().isEmpty() || mDataBinding.etUseTaxLoan.getText().toString().isEmpty()) {
            ToastUtils.showShort(getString(R.string.please_input_amount));
            return;
        }
        repayAmount = (int) (loanAmount * rate * selYear+loanAmount);
        payInterest = repayAmount - loanAmount;
        monthPay = repayAmount / selYear / 12;
        licenceLoan = Integer.parseInt(mDataBinding.etLicenceLoan.getText().toString());
        useTaxLoan = Integer.parseInt(mDataBinding.etUseTaxLoan.getText().toString());
        sumAmount = priceLoan + payInterest + taxLoan + licenceLoan + useTaxLoan + bxLoan;
        resultLoanDialog();
        myResultLoanDialog.show();
    }

    private void clearSelection() {
        mDataBinding.tvBuyAll.setTextColor(Color.parseColor("#99FFFFFF"));
        mDataBinding.tvBuyAll.setTypeface(Typeface.DEFAULT);
        mDataBinding.tvBuyAll.setBackground(null);
        mDataBinding.tvBuyLoan.setTextColor(Color.parseColor("#99FFFFFF"));
        mDataBinding.tvBuyLoan.setTypeface(Typeface.DEFAULT);
        mDataBinding.tvBuyLoan.setBackground(null);
    }

    //全款购车交强险弹框
    private void bxAllDialog() {
        myBxAllDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_bx, null);
        myBxAllDialog.setContentView(inflate);
        myBxAllDialog.setCancelable(true);
        Window dialogWindow = myBxAllDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView cancel = inflate.findViewById(R.id.tvDialogBxCancel);
        ImageView right = inflate.findViewById(R.id.ivDialogBxRight);
        StkRecycleView bxList = inflate.findViewById(R.id.rvDialogBxList);
        List<MyBxBean> list = new ArrayList<>();
        list.add(new MyBxBean(getString(R.string.buy_bx1), true));
        list.add(new MyBxBean(getString(R.string.buy_bx2), false));
        bxList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        bxAllAdapter = new BxAdapter();
        bxAllAdapter.setList(list);
        bxList.setAdapter(bxAllAdapter);
        bxAllAdapter.setOnItemClickListener(this);
        cancel.setOnClickListener(this);
        right.setOnClickListener(this);
    }

    //全款购车计算结果弹框
    private void resultAllDialog() {
        myResultAllDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_result_all, null);
        myResultAllDialog.setContentView(inflate);
        myResultAllDialog.setCancelable(true);
        Window dialogWindow = myResultAllDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView result = inflate.findViewById(R.id.tvDialogResultAllText);
        ImageView cancel = inflate.findViewById(R.id.ivDialogResultAllCancel);
        result.setText(resultAll + "");
        cancel.setOnClickListener(this);
    }

    //贷款购车首付款弹框
    private void sfkDialog() {
        mySfkDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_sfk, null);
        mySfkDialog.setContentView(inflate);
        mySfkDialog.setCancelable(true);
        Window dialogWindow = mySfkDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView cancel = inflate.findViewById(R.id.tvDialogSfkCancel);
        ImageView right = inflate.findViewById(R.id.ivDialogSfkRight);
        StkRecycleView sfkList = inflate.findViewById(R.id.rvDialogSfkList);
        List<MyBxBean> list = new ArrayList<>();
        list.add(new MyBxBean(getString(R.string.sfk_text1), true));
        list.add(new MyBxBean(getString(R.string.sfk_text2), false));
        list.add(new MyBxBean(getString(R.string.sfk_text3), false));
        list.add(new MyBxBean(getString(R.string.sfk_text4), false));
        sfkList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        sfkAdapter = new BxAdapter();
        sfkAdapter.setList(list);
        sfkList.setAdapter(sfkAdapter);
        sfkAdapter.setOnItemClickListener(this);
        cancel.setOnClickListener(this);
        right.setOnClickListener(this);
    }

    //贷款购车贷款年限弹框
    private void loanYearDialog() {
        myLoanYearDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_loan_year, null);
        myLoanYearDialog.setContentView(inflate);
        myLoanYearDialog.setCancelable(true);
        Window dialogWindow = myLoanYearDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView cancel = inflate.findViewById(R.id.tvDialogLoanYearCancel);
        ImageView right = inflate.findViewById(R.id.ivDialogLoanYearRight);
        StkRecycleView LoanYearList = inflate.findViewById(R.id.rvDialogLoanYearList);
        List<MyBxBean> list = new ArrayList<>();
        list.add(new MyBxBean(getString(R.string.loan_year1), false));
        list.add(new MyBxBean(getString(R.string.loan_year2), true));
        list.add(new MyBxBean(getString(R.string.loan_year3), false));
        list.add(new MyBxBean(getString(R.string.loan_year4), false));
        list.add(new MyBxBean(getString(R.string.loan_year5), false));
        LoanYearList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        loanYearAdapter = new BxAdapter();
        loanYearAdapter.setList(list);
        LoanYearList.setAdapter(loanYearAdapter);
        loanYearAdapter.setOnItemClickListener(this);
        cancel.setOnClickListener(this);
        right.setOnClickListener(this);
    }

    //贷款购车交强险弹框
    private void bxLoanDialog() {
        myBxLoanDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_bx_loan, null);
        myBxLoanDialog.setContentView(inflate);
        myBxLoanDialog.setCancelable(true);
        Window dialogWindow = myBxLoanDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView cancel = inflate.findViewById(R.id.tvDialogBxLoanCancel);
        ImageView right = inflate.findViewById(R.id.ivDialogBxLoanRight);
        StkRecycleView bxList = inflate.findViewById(R.id.rvDialogBxLoanList);
        List<MyBxBean> list = new ArrayList<>();
        list.add(new MyBxBean(getString(R.string.buy_bx1), true));
        list.add(new MyBxBean(getString(R.string.buy_bx2), false));
        bxList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        bxLoanAdapter = new BxAdapter();
        bxLoanAdapter.setList(list);
        bxList.setAdapter(bxLoanAdapter);
        bxLoanAdapter.setOnItemClickListener(this);
        cancel.setOnClickListener(this);
        right.setOnClickListener(this);
    }

    //贷款购车计算结果弹框
    private void resultLoanDialog() {
        myResultLoanDialog = new Dialog(mContext, R.style.DialogStyle);
        View inflate = LayoutInflater.from(mContext).inflate(R.layout.dialog_result_loan, null);
        myResultLoanDialog.setContentView(inflate);
        myResultLoanDialog.setCancelable(true);
        Window dialogWindow = myResultLoanDialog.getWindow();
        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        DisplayMetrics dm = getResources().getDisplayMetrics();
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = (int) (dm.widthPixels * 0.9);
        lp.y = 50;
        // 将属性设置给窗体
        dialogWindow.setAttributes(lp);
        TextView month = inflate.findViewById(R.id.tvDialogResultLoanMonthPay);
        TextView sum = inflate.findViewById(R.id.tvDialogResultLoanSumAmount);
        TextView interest = inflate.findViewById(R.id.tvDialogResultLoanPayInterest);
        TextView amount = inflate.findViewById(R.id.tvDialogResultLoanRepayAmount);
        ImageView cancel = inflate.findViewById(R.id.ivDialogResultLoanCancel);
        month.setText(monthPay + "");
        sum.setText(sumAmount + "");
        interest.setText(payInterest + "");
        amount.setText(repayAmount + "");
        cancel.setOnClickListener(this);
    }


}